Attribute to only be editable from trigger

How can I set up an attibute to only be editable from 2 triggers that I already have?

So, I have an attribute pre-save trigger that displays a dialog and ask for a "change reaosn", then takes the user input and puts it into another attribute (change reasons).
I want to limit the modifications to the "change reason" attribute to only that trigger code.
In other words make an attribute that is editable only by DXL code.

Thank you,
Octavian
ostanescu - Thu Jul 08 11:03:09 EDT 2010

Re: Attribute to only be editable from trigger
Mathias Mamsch - Thu Jul 08 13:34:39 EDT 2010

I think, this can work if you implement the trigger to fire on modifications of both attributes. The trigger needs to prevent all changes to the second attribute. However if the trigger itself changes the second attribute, then it will not be called again so the modification will be allowed! I noticed that at least for DOORS 8.2 changes that a trigger does will not fire the same trigger again.

Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Attribute to only be editable from trigger
ostanescu - Thu Jul 08 14:08:09 EDT 2010

Hi,
Good idea, but I don't think is possible.
How do you define a trigger for 2 attributes? Not 2 triggers with the same code.

Here is what I tried:

string trig_dxl = "Trigger t = current \n
AttrDef ad = attrdef t \n
ack ad.name \"\" \n
Object o = object t
o.\"_Change Reason\" = \"test\" "

//install on first attribute
Trigger t = trigger("test", module->object->attribute->"Object Text", pre, save, 10, trig_dxl)

//install on second attribute
t = trigger("test", module->object->attribute->"_Change Reason", pre, save, 10, trig_dxl)

if(null t) ack "Trigger not installed"
else ack "Trigger installed"
So, this code installs 2 triggers with the same name.

Re: Attribute to only be editable from trigger
ostanescu - Thu Jul 08 15:02:10 EDT 2010

Hi,
I actually solved this issue.
It is possible to install a trigger for all attribute changes.
So, in the trigger code I will have to execute different code based on the name of the attribute.

Trigger t = trigger("T_Name", module->object->attribute, pre, save, 10, DXL_CODE)

this trigger will fire on all attribute changes, so in the DXL_CODE there will be logic to execute based on which attribtue was changed.
Something like:

Trigger t = current Trigger
Module m = module t
if(!isVisible m) halt
Object o = object t
AttrDef ad = attrdef t
string atName = ad.name

if(atName == "Object Text") {
- get reason for change
- record reason for change in "_Change Reason" attribtue
set trigPreConPass
}
else if(atName == "_Change Reason") {
ack "You cannot change this atttribute manually"
set trigPreConFail
}
And this trigger only executes once and allows changes to any other attribute from within, without firing again.

Thank you for stering me in the right direction,
Octavian

Re: Attribute to only be editable from trigger
ostanescu - Thu Jul 08 15:16:26 EDT 2010

Done

Re: Attribute to only be editable from trigger
Mathias Mamsch - Thu Jul 08 16:54:55 EDT 2010

ostanescu - Thu Jul 08 15:02:10 EDT 2010
Hi,
I actually solved this issue.
It is possible to install a trigger for all attribute changes.
So, in the trigger code I will have to execute different code based on the name of the attribute.

Trigger t = trigger("T_Name", module->object->attribute, pre, save, 10, DXL_CODE)

this trigger will fire on all attribute changes, so in the DXL_CODE there will be logic to execute based on which attribtue was changed.
Something like:

Trigger t = current Trigger
Module m = module t
if(!isVisible m) halt
Object o = object t
AttrDef ad = attrdef t
string atName = ad.name

if(atName == "Object Text") {
- get reason for change
- record reason for change in "_Change Reason" attribtue
set trigPreConPass
}
else if(atName == "_Change Reason") {
ack "You cannot change this atttribute manually"
set trigPreConFail
}


And this trigger only executes once and allows changes to any other attribute from within, without firing again.

Thank you for stering me in the right direction,
Octavian

well done...

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Attribute to only be editable from trigger
llandale - Thu Jul 08 18:13:54 EDT 2010

Don't have time to read all the posts. Had some luck with an almost identical chore.

Preamble: you can enable and disable triggers at will. However, triggers will still run for standard users, even when disabled. So a clever trigger will check the trigger state, and if its disabled then the trigger halts itself. Notice that for DB admins and triggers are disabled, the trigger never fires and therefore has the same result.

Make a pre-save-attr trigger for your attribute 'Change Reason'. That trigger will prevent all changes if triggers are enabled. If triggers are disabled, the change is allowed.

Your existing pres-save-attr trigger for your attribute 'Requirement' will disable triggers, set the 'Change Reason', then enable them again. ..err.. I mean it will set the trigger state back to what it was when the trigger fired.

// pre-save-attr-trigger for 'change Reason'
if (getTriggerState_()) { set(trigPreConFail); halt }
 
// pre-save-attr-trigger for 'Requirement'
bool   TrigState = getTiggerState_()
obj."Change Reason" = "A good reason"
setTriggerState_(TrigState)

 


Another approach would be to define an environment variable, perhaps named "ProtectChangeReason". Trigger 'Requirement' sets it to a value, updates the reason, then clears the value. Trigger
Reason only allows the update when the Protect has the right value

 

 

string Value = getenv("ProtectChangeReason")
if (null Value) {set(trigPreConFail); halt}
 
setenv("ProtectChangeReason", "Allow")
obj."Change Reason" = "A good reason"
setenv("ProtectChangeReason", "")



I'm starting to like that 2nd approach more, but it does stick a value permamantly in the Registry.



 

 

 

  • Louie

 

 

Re: Attribute to only be editable from trigger
Peter_Albert - Fri Jul 09 03:03:31 EDT 2010

ostanescu - Thu Jul 08 15:02:10 EDT 2010
Hi,
I actually solved this issue.
It is possible to install a trigger for all attribute changes.
So, in the trigger code I will have to execute different code based on the name of the attribute.

Trigger t = trigger("T_Name", module->object->attribute, pre, save, 10, DXL_CODE)

this trigger will fire on all attribute changes, so in the DXL_CODE there will be logic to execute based on which attribtue was changed.
Something like:

Trigger t = current Trigger
Module m = module t
if(!isVisible m) halt
Object o = object t
AttrDef ad = attrdef t
string atName = ad.name

if(atName == "Object Text") {
- get reason for change
- record reason for change in "_Change Reason" attribtue
set trigPreConPass
}
else if(atName == "_Change Reason") {
ack "You cannot change this atttribute manually"
set trigPreConFail
}


And this trigger only executes once and allows changes to any other attribute from within, without firing again.

Thank you for stering me in the right direction,
Octavian

Just an additional proposal: In your set-up, if people have spent some time editing the "Object Text" and only realize after the trigger fires that they forgot to put something in "_Change Reason", then all their work is lost. I am therefore adding a little DB to my trigger code (after setting trigPreConFail), which displays the new attribute value before it is discarded. This at least gives the option to copy / paste the text into a different application in order to save the work for later use, once _Change Reason" is fixed.
 

...
set(trigPreConFail)
Buffer attNewValue = create
value(trg, attNewValue)
DB attributeAccessDB = topMost "Attribute value access rights"
DBE infoDBE = text(attributeAccessDB, "", "You can't edit this attribute", 300, 100, true)
DBE attrValueDBE = richText(
  attributeAccessDB, 
  "Proposed new text:", 
  richText(tempStringOf attNewValue), 
  DBE_WIDTH, 100, true)
realize attributeAccessDB
delete attNewValue
show attributeAccessDB
...

Re: Attribute to only be editable from trigger
ostanescu - Fri Jul 09 14:27:45 EDT 2010

Hi,
Thank you the additional solutions.
I didn't know there is a trigger state, I will use it next time.
For me the best approach is with the single trigger for all attributes, because:
1. there are 2 attributes to be monitorized in the 2 attributes: _Change Reason and _SPR, from which _SRP can be manually edited, but _Change Reason not.
2. also those 2 attributes are going to have some initial default values and the very first change is allowed, only subsequent changes will need a "good reason" to be saved.
3. code stays within one file, and is very similar, in fact I can share it with you, the file is text format.

Octavian

PS: the .trigger extension is used by a generic script that installs triggers.
Attachments

attachment_14485302_theTrigger.trigger